package com.ysd.lis.service.lab.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.lab.LabDictitemVsChannel;
import com.ysd.lis.mapper.lab.LabDictitemVsChannelMapper;
import com.ysd.lis.request.lab.LabDictitemVsChannelDto;
import com.ysd.lis.service.lab.LabDictitemVsChannelService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 报告项目通道号转译对照 服务实现类
 * </p>
 *
 * @author bai
 * @since 2024-12-18
 */
@Service
public class LabDictitemVsChannelServiceImpl extends ServiceImpl<LabDictitemVsChannelMapper, LabDictitemVsChannel> implements LabDictitemVsChannelService {

    @Override
    public Result findDictitemVsChannelList(LabDictitemVsChannel channel) {
        if (StringUtils.isBlank(channel.getRptGroup())||StringUtils.isBlank(channel.getItemNo())|| StringUtils.isBlank(channel.getInstrCode())|| StringUtils.isBlank(channel.getChannelCode())){
            return Result.succ(1,"查询成功",null);
        }
        LambdaQueryWrapper<LabDictitemVsChannel>queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(LabDictitemVsChannel::getRptGroup,channel.getRptGroup());
        queryWrapper.eq(LabDictitemVsChannel::getItemNo,channel.getItemNo());
        queryWrapper.eq(LabDictitemVsChannel::getInstrCode,channel.getInstrCode());
        queryWrapper.eq(LabDictitemVsChannel::getChannelCode,channel.getChannelCode());
        queryWrapper.eq(LabDictitemVsChannel::getDelFlag,0);
        return Result.succ(1,"查询成功",this.list(queryWrapper));
    }

    @Override
    public Result deleteDictitemVsChannel(LabDictitemVsChannelDto dictitemVsChannelDto) {
        this.removeByIds(dictitemVsChannelDto.getItemVsChanneIds());
        return Result.succ(1,"删除成功",null);
    }

    @Override
    public Result addDictitemVsChannel(LabDictitemVsChannel labDictitemVsChannel) {
        LambdaQueryWrapper<LabDictitemVsChannel>queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(LabDictitemVsChannel::getRptGroup,labDictitemVsChannel.getRptGroup());
        queryWrapper.eq(LabDictitemVsChannel::getItemNo,labDictitemVsChannel.getItemNo());
        queryWrapper.eq(LabDictitemVsChannel::getInstrCode,labDictitemVsChannel.getInstrCode());
        queryWrapper.eq(LabDictitemVsChannel::getChannelCode,labDictitemVsChannel.getChannelCode());
        queryWrapper.eq(LabDictitemVsChannel::getFeeCode,labDictitemVsChannel.getFeeCode());
        queryWrapper.eq(LabDictitemVsChannel::getDelFlag,0);
        List<LabDictitemVsChannel> list = this.list(queryWrapper);
        if (list.size()>0){
            return Result.succ(1, "新增成功", null);
        }
        boolean save = this.save(labDictitemVsChannel);
        if (save) {
            return Result.succ(1, "新增成功", null);
        } else {
            return Result.fail("添加失败！");
        }
    }

    @Override
    public Result saveLabDictitemVsChannelList(List<LabDictitemVsChannel> labDictitemVsChannel) {
        boolean b = this.saveOrUpdateBatch(labDictitemVsChannel);
        if (b) {
            return Result.succ(1, "保存成功", null);
        } else {
            return Result.fail("保存失败！");
        }
    }
}
